import json
from pyecharts.charts import Map
from pyecharts.options import *
f = open("E:/疫情.txt", "r", encoding="UTF-8")
data = f.read()
data = json.loads(data)
data_henan_list = data["areaTree"][0]["children"][3]["children"]
data_list = []
data_list.append(("济源市", "5"))
for henan_city in data_henan_list:
    city_name = henan_city["name"] + "市"
    city_confirm = henan_city["total"]["confirm"]
    data_list.append((city_name, city_confirm))
map1 = Map()
map1.add("河南省疫情分布", data_list, "河南")
map1.set_global_opts(
    title_opts=TitleOpts(title="河南省疫情分布", pos_left="center", pos_bottom="1%"),
    toolbox_opts=ToolboxOpts(is_show=True),
    visualmap_opts=VisualMapOpts(
        is_show=True,
        is_piecewise=True,
        pieces=[
            {"min": 1, "max": 9, "label": "1-9人", "color": "#CCFFFF"},
            {"min": 10, "max": 49, "label": "10-49人", "color": "#FFFF99"},
            {"min": 50, "max": 99, "label": "50-99人", "color": "#FF9966"},
            {"min": 100, "max": 199, "label": "100-199人", "color": "#FF6666"},
            {"min": 200, "max": 299, "label": "200-299人", "color": "#CC3333"},
            {"min": 300, "label": "300以上", "color": "#990033"},
        ]
    )
)
f.close()
map1.render()
